"""
Compliance Template 合规模板表模型
"""
import uuid
from datetime import datetime
from sqlalchemy import Column, Text, String, DateTime, Integer
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from db.base import Base

class ComplianceTemplate(Base):
    """合规模板数据模型"""
    __tablename__ = "compliance_template"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    name = Column(String(255), nullable=False, unique=True, comment="模板名称")
    description = Column(Text, nullable=True, comment="模板描述")
    assessment_type = Column(
        String(20), 
        nullable=False, 
        comment="模板评估类型"
    )
    default_maturity_level = Column(
        Integer,
        nullable=False,
        default=1,
        comment="默认成熟度等级"
    )
    version = Column(
        String(20), 
        nullable=False, 
        default='1.0.0', 
        comment="版本号"
    )
    created_at = Column(
        DateTime(timezone=True),
        default=datetime.now,
        nullable=False,
        comment="创建时间"
    )
    updated_at = Column(
        DateTime(timezone=True),
        default=datetime.now,
        onupdate=datetime.now,
        nullable=False,
        comment="更新时间"
    )

    # 关系定义，与template_item表的关系
    template_items = relationship("TemplateItem", back_populates="template", cascade="all, delete-orphan")
    assessment_plans = relationship("AssessmentPlan", back_populates="template")
